load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRF_contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/ut_string.ncl"
load "/public/users/wrf/Codes/WRF_scripts/utils/substring.ncl"
load "/public/users/wrf/Codes/WRF_scripts/utils/WRF_dyy_contributed.ncl"

; open wrfout file to get the domain lat/lon information
wrfout_file = "/public/users/wrf/wrfout/2012111420/wrfout_d01_2012-11-14_12:00:00"
a = addfile(wrfout_file + ".nc", "r")
xlong = wrf_user_getvar(a, "XLONG", 0)
xlat  = wrf_user_getvar(a, "XLAT", 0)

i = 1
j = 1
lon0 = xlong(j,i)
lat0 = xlat(j,i)

print(i)
print(j)
print(lon0)
print(lat0)

lonlat1 = wrf_user_ij_to_ll(a, i+1,j+1,True)
print(lonlat1)
ij1 = wrf_user_ll_to_ij(a, lonlat1(0), lonlat1(1), True) - 1
print(ij1)
